<?php

namespace App\Http\Resources\Apps;

use App\Models\Notice;
use Illuminate\Http\Resources\Json\JsonResource;

class UserResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    public function toArray($request)
    {
        $notice = Notice::latest()->first();

        return [
            'id'    => $this['id'],
            'mobile'=> $this['mobile'],
            'nickname' => $this['nickname'],
            'icon'  => $this['icon'],
            'balance' => $this['balance'],
            'sign_in' => collect($this['sign'])->where('date',date('Y-m-d')) ? 1 :0,
            'notice'  => $notice ? $notice->content : '',
            'is_admin'=> $this['is_admin'],
            'invite'  => $this['invite'],
            'invite_name'   => $this['invite'] ? $this['invite_user']['name'] : '',
            'name'  => $this['name'],
            'identity'  => $this['identity'],
            'address'   => $this['address'],
        ];
    }
}
